feat(swap): /swap page powered by 0x Swap API v2 - #92
Merged
Conversation
Adds an ERC-20 swap experience on Base with best execution across 150+ DEXes. - /api/0x/price + /api/0x/quote proxy 0x's allowance-holder endpoints, keeping ZEROX_API_KEY server-side and injecting affiliate fee params (swapFeeRecipient/swapFeeBps/swapFeeToken) only when the client opts in with ?fee=1 and GNARS_FEE_RECIPIENT is configured. - /swap renders SwapWidget: token pickers, debounced indicative price, ERC-20 approval flow (prepareContractCall + thirdweb sendTransaction), swap execution via prepareTransaction on the firm 0x quote, network fee display, wrong-network "Switch to Base" CTA, and an opt-in "Support Gnars treasury" checkbox (default checked). - Default token list: ETH / WETH / USDC / GNARS / DEGEN / HIGHER on Base. - Header nav: collapses Treasury under a new "Money" dropdown that also hosts the Swap entry. - Docs: docs/integrations/swap.md describes the architecture, env vars, and fee model; INDEX.md updated to point at it. - env.example: ZEROX_API_KEY, GNARS_FEE_RECIPIENT, GNARS_FEE_BPS. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@sktbrd is attempting to deploy a commit to the r4to's projects Team on Vercel. A member of the Team first needs to authorize it. |
Drops GNARS_FEE_RECIPIENT and GNARS_FEE_BPS env vars in favor of: - swapFeeRecipient -> DAO_ADDRESSES.treasury (already canonical in config) - swapFeeBps -> SWAP_FEE_BPS = 50 (new constant in src/lib/config.ts) ZEROX_API_KEY remains the only required env var. Fee destination and rate now ship with the code so they're auditable in git rather than hidden in deploy-time secrets. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/swappage that lets users trade ETH, WETH, USDC, GNARS, and a few other Base ERC-20s through the 0x Swap API v2, routed viaallowance-holder/priceandallowance-holder/quote./api/0x/price,/api/0x/quote) hold theZEROX_API_KEYand inject opt-in affiliate fee params (swapFeeRecipient/swapFeeBps/swapFeeToken) only when the client passes?fee=1ANDGNARS_FEE_RECIPIENTis configured.Changes
src/app/swap/page.tsx— server component, page metadata + canonical, renders<SwapWidget />.src/app/swap/SwapWidget.tsx— client component with token pickers (shadcnDialog), debounced 0x indicative price, ERC-20 approval flow (prepareContractCall+ thirdwebsendTransaction), swap execution viaprepareTransactionon the firm 0x quote, network-fee display, wrong-network "Switch to Base" CTA, and an opt-in "Support Gnars treasury (0.5% fee)" checkbox (default checked).src/app/api/0x/price/route.ts&src/app/api/0x/quote/route.ts— Edge-style proxy routes; identical fee-injection logic so the price preview and the firm quote stay consistent.src/components/layout/DaoHeader.tsx— converts the Treasury top-level link into a Money dropdown containing Treasury and Swap.env.example— documentsZEROX_API_KEY,GNARS_FEE_RECIPIENT,GNARS_FEE_BPS.docs/integrations/swap.md— architecture, flow, env vars, fee model, and intentional deviations from the SkateHive reference.docs/INDEX.mdupdated to point at it.Architectural notes (vs. SkateHive reference)
sonnertoasts.useWriteAccount()so the SA-vs-EOA view-mode toggle keeps working.Required env vars
ZEROX_API_KEY500without it.GNARS_FEE_RECIPIENTGNARS_FEE_BPS50(0.5%).Test plan
/swapcleanly; metadata shows "Swap — Gnars DAO".0.001ETH → buy GNARS: indicative price renders within ~600ms, network fee shows, "Swap" button enables./api/0x/priceno longer carriesfee=1; ticking again puts it back.pnpm lintclean (1 pre-existing warning inBountiesView.tsx).pnpm buildclean —/swaplisted as a static route.Generated with Claude Code